/*
 * \brief  C-library back end
 * \author Norman Feske
 * \date   2008-11-11
 *
 * Currently, we direct all output to the log console. There is no support for
 * writing to files or sockets or other output streams.
 */

/*
 * Copyright (C) 2008-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#include <string.h>

/* interface to 'log_console' */
extern "C" int stdout_write(const char *);

extern "C" int _write(void *fp, const char *buf, int len)
{
	int orig_len = len;
	while (len > 0) {
		char tmp[64];
		int curr_len = len >= sizeof(tmp) - 1 ? sizeof(tmp) - 1 : len;
		strncpy(tmp, buf, curr_len);
		tmp[curr_len > 0 ? curr_len - 1 : 0] = 0;
		stdout_write(tmp);
		len -= curr_len;
		buf += curr_len;
	}
	return orig_len;
}
